package com.jiangnan.mapper;

import com.jiangnan.pojo.Student;
import com.jiangnan.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    public List<Student> getPage(StudentQueryParam studentQueryParam);

    void deleteBatch(List<Integer> ids);

    @Insert("insert into student (name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id," +
            "                     create_time, update_time)" +
            "values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate}," +
            "#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);

    @Select("select * from student where id = #{id}")
    Student getById(Integer id);

    void update(Student student);

    @Update("update student set violation_count = violation_count + 1 ," +
            " violation_score = violation_score + #{score}," +
            "update_time = now()" +
            " where id = #{id}")
    void updateViolation(Integer id, Integer score);

    @Select("select c.name name, count(*) num from student s left join clazz c on s.clazz_id = c.id group by clazz_id order by count(*)")
    List<Map<String, Object>> getStudentCountData();

    List<Map<String, Object>> getStudentDegreeData();
}
